$(function() {
  $(document).on("pageInit", "#page-index", function(e, id, page) {
	  $("#banner").swiper({pagination : '#banner-nav'});
	  $("#hd-banner").swiper({pagination : '#hd-banner-nav'});
	  $("#sgnews").swiper({direction: 'vertical',wrapperClass :'sgnews',autoplay:'3000'});
	  $("#docnews").swiper({direction: 'vertical',wrapperClass :'sgnews',autoplay:'3000'});
		var loadConfig = {
						url_api:'/plus/list.php',
						page:2,
						pagesize:2,
						loading : 0,
						channelid:18,
						addfield:'zhicheng,touxian1,touxiang',
						order:'weight',
						}
		function  loadMoreApply(){
			if(loadConfig.loading == 0){
				 var typeid = loadConfig.typeid;
				 var page = loadConfig.page;
				 var channelid = loadConfig.channelid;
				 var addfield = loadConfig.addfield;
				 var order = loadConfig.order;
				 var pagesize = loadConfig.pagesize;
				 var url = loadConfig.url_api,data={ajax:'pullload',typeid:typeid,page:page,pagesize:pagesize,channelid:channelid,addfield:addfield,order:order};
					 
					function ajax(url, data) {
						$.ajax({url: url,data:data,async: false,type: 'GET',dataType: 'json',success:function(data) {
						
							addContent(data);	
							
						}});
						
					}
					ajax(url,data);
			}
		}
		 function addContent (rs){
			if(rs.statu== 1){
				var data = rs.list;
				var total = rs.total;
				var arr=[];
				var len = data.length;
				for(var i=0;i<len;i++){
					arr.push('<a href="'+data[i].arcurl+'" class="external">');
					arr.push('<li>');
					arr.push('<img src="'+data[i].touxiang+'">');
					arr.push('<div class="doc-title">'+data[i].title);
					arr.push('<p>'+data[i].zhicheng+'</p>');
					arr.push('<p>'+data[i].typename+'</p>');
					arr.push('</div>');
					arr.push('</li>');
					arr.push('</a>');								
				}
				$('#ajax-list').html(arr.join(''));
			
				loadConfig.load_num = rs.load_num;
			
				if(total<loadConfig.page*loadConfig.pagesize || loadConfig.page > loadConfig.load_num){
					loadConfig.page =1 ;
				}else{
				loadConfig.page++;
				
				loadConfig.loading = 0;}
			}
		}
		function pullLoad(){
			document.getElementById("loadlist").addEventListener('click', loadMoreApply, false);
		}
		pullLoad();

		  $("#xmall").click(function(){
			$(".xm-list-content:nth-child(2)").toggle();
			$(this).hasClass("hide")?($(this).removeClass("hide")):($(this).addClass("hide"));
		  });
		  $("#xm-refresh").click(function(){
			  var xm1= $(".xm-list-content:first-child").html();
			  var xm2= $(".xm-list-content:nth-child(2)").html()
			$(".xm-list-content:first-child").html(xm2);
			 $(".xm-list-content:nth-child(2)").html(xm1);
		  });
		  $("#showall").click(function(){
			$(".show-list li:nth-child(4)").toggle();
			$(".show-list li:nth-child(5)").toggle();
			$(this).hasClass("hide")?($(this).removeClass("hide")):($(this).addClass("hide"));
		  });

  });
  $(document).on("pageInit", "#page-pinpai", function(e, id, page) {
	  $("#pp-banner").swiper({pagination : '#pp-banner-nav'});
  });

  $(document).on("pageInit", "#page-list-doc", function(e, id, page) {
	  $("#docnews").swiper({direction: 'vertical',wrapperClass :'sgnews',autoplay:'3000'});
  });

  $(document).on("pageInit", "#page-article-doc", function(e, id, page) {
	  $("#anli-list").swiper({pagination : '#anli-nav'});
  });

  $(document).on("pageInit", "#page-article-xm", function(e, id, page) {
	  $("#anli-list").swiper({pagination : '#anli-nav'});
	  $("#doc-list").swiper({pagination : '#doc-nav'});
	  $("#hdnews").swiper({direction: 'vertical',wrapperClass :'sgnews',autoplay:'3000'});
  });  

  $(document).on("pageInit", "#page-zt", function(e, id, page) {
	  $("#banner").swiper({pagination : '#banner-nav'});
	  $("#banne").swiper({pagination : '#banner-nav1'});
	  $("#zt-anli").swiper({pagination : '#anli-nav'});
	  $("#zt-doc").swiper({pagination : '#doc-nav'});
	 $("#layout8-swiper").swiper({pagination : '#layout8-nav'});
  });  

  $(document).on("pageInit", "#page-list-anli", function(e, id, page) {
	  $("#hot-tag-more").click(function(){console.log(1);
	  $(".hot-tag").hasClass("open")?($(".hot-tag").removeClass("open")):($(".hot-tag").addClass("open"));
	  });

  });

  $(document).on("pageInit", "#page-list-anli", function(e, id, page) {
	  $("#hot-tag-more").click(function(){console.log(2);
	  $(".hot-tag").hasClass("open")?($(".hot-tag").removeClass("open")):($(".hot-tag").addClass("open"));
	  });
  });

  $(document).on("pageInit", "#page-list-riji", function(e, id, page) {
	   $("#hd-banner").swiper({pagination : '#hd-banner-nav'});
	   $("#banner").swiper({pagination : '#banner-nav'});
		var loadConfig = {
						url_api:'/plus/list.php',
						page:5,
						pagesize:2,
						loading : 0,
						channelid:19,
						order:'weight',
						noflag:'h,c',
						}
		function  loadMoreApply(){
			if(loadConfig.loading == 0){
				 var page = loadConfig.page;
				 var channelid = loadConfig.channelid;
				 var order = loadConfig.order;
				 var noflag = loadConfig.noflag;
				 var pagesize = loadConfig.pagesize;
				 var url = loadConfig.url_api,data={ajax:'pullload',page:page,pagesize:pagesize,channelid:channelid,order:order,noflag:noflag};
					 
					function ajax(url, data) {
						$.ajax({url: url,data:data,async: false,type: 'GET',dataType: 'json',success:function(data) {
						
							addContent(data);	
							
						}});
						
					}
					ajax(url,data);
			}
		}
		 function addContent (rs){
			if(rs.statu== 1){
				var data = rs.list;
				var total = rs.total;
				var arr=[];
				var len = data.length;
				for(var i=0;i<len;i++){
					arr.push('<li>');
					arr.push('<a href="'+data[i].arcurl+'" class="item-link item-content">');
					arr.push('<div class="item-media"><img src="'+data[i].picname+'" style="width: 4rem;"></div>');
					arr.push('<div class="item-inner">');
					arr.push('<div class="item-title-row">');
					arr.push('<div class="item-title">'+data[i].title+'</div>');
					arr.push('</div>');
					arr.push('<div class="item-text">'+data[i].infos+'...</div>');
					arr.push('</div>');
					arr.push('</a>');
					arr.push('<li>');									
				}
				$('#ajax-list').append(arr.join(''));
			
				loadConfig.load_num = rs.load_num;
			
				if(total<loadConfig.page*loadConfig.pagesize || loadConfig.page > loadConfig.load_num){
					$('#loadlist').remove();
					document.getElementById("loadlist").removeEventListener('click',loadMoreApply,false);
				}else{
				loadConfig.page++;
				
				loadConfig.loading = 0;}
			}
		}
		function pullLoad(){
			if(document.getElementById("loadlist")){
				document.getElementById("loadlist").addEventListener('click', loadMoreApply, false);
			}
		}
		pullLoad();

	  $("#hot-tag-more").click(function(){console.log(3);
	  $(".hot-tag").hasClass("open")?($(".hot-tag").removeClass("open")):($(".hot-tag").addClass("open"));
	  });

  });

    $(document).on("pageInit", "#page-list-arc", function(e, id, page) {
var loadConfig = {
				url_api:'/plus/list.php',
				typeid:typeid,
				page:3,
				pagesize:2,
				loading : 0,
				
				}
function  loadMoreApply(){
	if(loadConfig.loading == 0){
		 var typeid = loadConfig.typeid;
		 var page = loadConfig.page;
		 var pagesize = loadConfig.pagesize;
		 var url = loadConfig.url_api,data={ajax:'pullload',typeid:typeid,page:page,pagesize:pagesize};
			 
			function ajax(url, data) {
				$.ajax({url: url,data:data,async: false,type: 'GET',dataType: 'json',success:function(data) {
				
					addContent(data);	
					
				}});
				
			}
			ajax(url,data);
	}
}
 function addContent (rs){
	if(rs.statu== 1){
		var data = rs.list;
		var total = rs.total;
		var arr=[];
		var len = data.length;
		for(var i=0;i<len;i++){
			arr.push('<li>');
			arr.push('<a href="'+data[i].arcurl+'" class="item-link item-content">');
			arr.push('<div class="item-media"><img src="'+data[i].picname+'" style="width: 4rem;"></div>');
			arr.push('<div class="item-inner">');
			arr.push('<div class="item-title-row">');
			arr.push('<div class="item-title">'+data[i].title+'</div>');
			arr.push('</div>');
			arr.push('<div class="item-text">'+data[i].infos+'...</div>');
			arr.push('</div>');
			arr.push('</a>');
			arr.push('<li>');					
		}
		$('#ajax-list').append(arr.join(''));
	
		loadConfig.load_num = rs.load_num;
	
		if(total<loadConfig.page*loadConfig.pagesize || loadConfig.page > loadConfig.load_num){
			$('#loadlist').remove();
			document.getElementById("loadlist").removeEventListener('click',loadMoreApply,false);
		}
		loadConfig.page++;
		
		loadConfig.loading = 0;
	}
}
function pullLoad(){
	document.getElementById("loadlist").addEventListener('click', loadMoreApply, false);
}
pullLoad();
  });

	$(document).on('click','.xmtab .xm-link', function () {
	  $.closeModal('.popup-menu');
	});
	$(function() {
	  $(".xmtab .content-menu .buttons-row").not(":nth-child(1),:nth-child(2),:nth-child(3)").addClass("none");
	  $(".xmtab #h-link").bind("click",function(){
		$(this).siblings(".buttons-row").not(":nth-child(1),:nth-child(2),:nth-child(3)").hasClass("none")?($(this).siblings(".buttons-row").not(":nth-child(1),:nth-child(2),:nth-child(3)").removeClass("none")):($(this).siblings(".buttons-row").not(":nth-child(1),:nth-child(2),:nth-child(3)").addClass("none"));
		$(this).find("a").hasClass("open")?($(this).find("a").removeClass("open")):($(this).find("a").addClass("open"));
	  });
	});

//	$(document).on("click", ".pull-right", function(e) {
//	$(this).hasClass("open-popup")?($(this).removeClass("open-popup").addClass("close-popup")):($(this).removeClass("close-popup").addClass("open-popup"));
//	});
	
	$(document).on("click", "#tab-link1", function(e) {
	$("#more1").show();
	$("#more2").hide();
	});
	$(document).on("click", "#tab-link2", function(e) {
	$("#more1").hide();
	$("#more2").show();
	});

	$(document).on("click", "#scrollTop", function(e) {
	$('.content').scrollTop(0);
	return false;  
	}); 

	$(document).on("pageInit", ".page", function(e, id, page) {
		$('a').each(function(){
			var href = $(this).attr('href');
			string=href.split("/");
			href=string[1];
			if(href=='zt'){
			$(this).addClass("external");
			}
		});

	var links = $("a[href$='/swt/']").add("a[href$='/goto-swt.html']");
	links.removeAttr('target');
	links.attr('href','javascript:void(0)');
	links.attr('onclick','openZoosUrl();return false;');
	links.attr('rel','nofollow');



	}); 


  $.init();
});